package com.abbas.smartCity.ui.govservice;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.abbas.smartCity.App;
import com.abbas.smartCity.R;
import com.abbas.smartCity.adapter.ListCommAdapter;
import com.abbas.smartCity.base.BaseActivity;
import com.abbas.smartCity.bean.gov.GovAppealListBean;
import com.abbas.smartCity.retroft.ICallback;
import com.bumptech.glide.Glide;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.List;

import retrofit2.Call;

public class AppealActivity extends BaseActivity {

    private ListView lv;
    private FloatingActionButton addBt;
    private List<GovAppealListBean.RowsBean> rows;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_appeal;
    }

    @Override
    protected String setCustomTitle() {
        return "诉求列表";
    }

    @Override
    protected void initView() {
        lv = (ListView) findViewById(R.id.lv);
        addBt = (FloatingActionButton) findViewById(R.id.add_bt);
    }

    @Override
    protected void initData() {
        final int id = getIntent().getIntExtra("id", -1);

        api.getAppealOfCategory(id).enqueue(new ICallback<GovAppealListBean>() {
            @Override
            public void onSuccess(Call<GovAppealListBean> call, GovAppealListBean data) {
                rows = data.getRows();

                lv.setAdapter(new ListCommAdapter<GovAppealListBean.RowsBean, ListCommAdapter.NewsHolder>(
                        rows,
                        ListCommAdapter.NewsHolder.class,
                        R.layout.news_item
                ) {
                    @Override
                    protected void show(GovAppealListBean.RowsBean data, View convertView, NewsHolder viewHolder, int position, Context context) {
                        Glide.with(context)
                                .load(App.getBaseUrl() + data.getImgUrl())
                                .into(viewHolder.im);
                        viewHolder.title.setText(data.getTitle());
                        viewHolder.sub.setText("承办单位："+data.getUndertaker());
                        viewHolder.tag2.setText("提交时间："+data.getCreateTime());
                        viewHolder.tag3.setText("处理状态："+data.getState());
                    }
                });
            }
        });
    }

    @Override
    protected void initEvent() {
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                final Intent intent = new Intent(AppealActivity.this, AppealDetailActivity.class);
                intent.putExtra("id",rows.get(i).getId());
            }
        });

        addBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(AddAppealActivity.class);
            }
        });
    }
}